package cn.jicheng;

import org.junit.Test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class test {

    @Test
    public void test1() {
        Customer customer = new Customer();
        customer.setCustName("你好");

        EntityManagerFactory factory = Persistence.createEntityManagerFactory("Jpa");
        EntityManager em = factory.createEntityManager();
        //获取事务
        EntityTransaction tx = em.getTransaction();
        //开启事务
        tx.begin();
        //保存
        em.persist(customer);
        //提交事务
        tx.commit();
        //释放资源
        em.close();
        factory.close();
    }
}
